package study.source.eunsung.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import study.source.common.util.EmailUtil;
import study.source.common.util.GmailSmtpSender;
import study.source.eunsung.service.EMailService;
import study.source.sunghun.service.email.MailService;

@Controller
@RequestMapping("/email")
public class EMailController {
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired private EMailService eMailService;
	
	@Autowired private MailService mailService;
	
	@RequestMapping( value = "/write", method = RequestMethod.GET)
	public String eMailView(){
		
		logger.debug("EMailViewController");
		
		return "eunsung/email/write";
	}
	
	@RequestMapping( value = "/send", method = RequestMethod.POST)
	public String eMailSend(ModelMap modelMap,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception{
		
		Map param = (Map) request.getAttribute("param");
		
		logger.debug(param.get("subject").toString());
		logger.debug(param.get("content").toString());
		
		//mailService.sendMail(param);
		
		GmailSmtpSender sender = new GmailSmtpSender();
		param.put("from", "les7414@naver.com");
		param.put("to", "les7414@naver.com");
		
		//sender.sendStmpMail(param);
		
		//emailUtil.sendMail(param);
		
		modelMap.addAttribute("result", "true");
		
		return "jsonView";
	}
	
	
}
